<?php 
	
	class signup extends content
	{
	var $category_parent;
	var $items;
	var $current_blog;
	var $author_data;
	var $videos;
	function signup()
	{
		mp('loading blog');
	}
	
	
	function digest()
	{
		global $conf;

		
		
		$category=new content_category();
		$category->where['id']=31;
		$category->get_category();
		
		if($category->piece['parent']>=18)
		{
			unset($category->where['id']);
			$category->where['id']=$category->piece['parent'];
			$category->get_category();
		 
		}
		//die($category->piece['id']);
		mp('got category');
		
		$this->get_videos($category->piece['id']);
		
		if($category->piece['type']=='video' && $category->piece['status']=='enabled')
		{
			mp('enabled video');
			$serial=unserialize($category->piece['serial']);
			$conf->style['masthead']=$category->piece['name'];
			$conf->style['background'].='background-image:url('.ap($serial["serial_style_background_image"]).');';
			$conf->style['background'].='background-color:#'.$serial["serial_style_background_color"].';';
			$conf->style['custom-masthead']=='color:#'.$serial["serial_style_masthead_color"].';';
			mp(ap($category->piece['image']));
				
			if(!empty($category->piece['image']))
			{
				$conf->style['masthead']='<img src="'.ap($category->piece['image']).'"/>';
			}
			
		}
		
		$this->display=TRUE;
		$this->category_parent = 31;
		$conf->page_render='assets/pages/signup.php';
	
	}
	
	function process_form()
	{
		
		$email = $_POST['email'];
		$uname = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $_POST['uname']);
		$password = $this->rand_passwd();
		$passwd = md5($password);
		$sql =  "insert into user(user_name,user_email,user_password,user_confirm,user_level) values('$uname','$email','$passwd',1,1)";
		
		if(mysql_query($sql))
		{
			$this->email($password,$uname,$email);
			
		}
		else	
			echo "Query failed: ".mysql_error();
	}
	function email($password,$username,$email)
	{
	
		
		$mail = new PHPMailer(); 
		$mail->IsSMTP(); // send via SMTP
		$mail->SMTPAuth = true; // turn on SMTP authentication
		$mail->Host = "smtp.gmail.com";
		$mail->Username = "josephedmundcastillo@gmail.com"; // SMTP username
		$mail->Password = "1123581321"; // SMTP password
		$webmaster_email = "tech@stratuscast.com"; //Reply to this email ID
		$email=$email; // Recipients email ID
		$name=" "; // Recipient's name
		$mail->From = $webmaster_email;
		$mail->FromName = "Pinoytuner";
		$mail->AddAddress($email,$name);
		$mail->AddReplyTo($webmaster_email,"Webmaster");
		$mail->WordWrap = 50; // set word wrap
		$mail->IsHTML(true); // send as HTML
		$mail->Subject = "Email Authentication";
		$mail->Body = "Welcome to PINOYTUNER, <br />
		Here is your username and password to login to PINOYTUNER <br />
		username: $username <br />
		password: $password"; //HTML Body
		$mail->AltBody = "Welcome to PINOYTUNER, \n
		Here is your username and password to login to PINOYTUNER \n
		username: $username \n
		password: $password"; //Text Body
		if(!$mail->Send())
		{
		echo "Mailer Error: " . $mail->ErrorInfo;
		}
		else
		{
		echo "Email has been sent! Check your email for login information";
		}

	
	}
	function rand_passwd( $length = 8, $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' ) 
	{
    
		
		return substr( str_shuffle( $chars ), 0, $length );
	
	}
}


?>